layui.define(['jquery', 'layer', 'suggest', 'configureCom', 'configure', 'sessionFun', 'bluebird'], function (exports) {
    var $ = layui.jquery;
    var layer = layui.layer;
    var suggest = layui.suggest;
    var configureCom = layui.configureCom;
    var configure = layui.configure;
    var sessionFun = layui.sessionFun;
    var matchType = layui.matchType;
    var pdfTimer;
    var obj;
    var pdfXiaoling = {
        /**
        * pdf初始化
        * id:控件id
        * fileId:文件id
        * url:图纸地址
        * boxId:外部承载div
        * */
        init: function (id, fileId, url, boxId) {
            // var html = '<object classid="clsid:7017318C-BC50-4DAF-9E4A-10AC8364C315" codebase="iStylePDF.cab#version=2,0,5,1103" id="' + id + '" height="100%"  width="100%" ></object>';
            var html = '<object classid="clsid:91fc4120-f2a6-4646-aae0-712df8c345b2" id="' + id + '" width="100%" height="100%"></object>';
            $(boxId).html(html);
            pdfTimer = setInterval(function () {
                try {
                    clearInterval(pdfTimer);
                    pdfTimer = null;
                    var obj = document.getElementById(id);//控件id
                    obj.OpenWebDocument(url);//打开图纸
                    var MarkupInfo = obj.GetMarkupInfo();//打开图纸
                    obj.SetMarkupInfo(fileId, MarkupInfo);//设置圈阅信息
                } catch (err) {
                    layer.alert('请安装pdf控件');
                }
            }, 700);
        },
        initNoCircle: function () {
            // var html = '<object classid="clsid:7017318C-BC50-4DAF-9E4A-10AC8364C315" codebase="iStylePDF.cab#version=2,0,5,1103" id="' + id + '" height="100%"  width="100%" ></object>';
            var html = '<object classid="clsid:91fc4120-f2a6-4646-aae0-712df8c345b2" id="' + id + '" width="100%" height="100%"></object>';
            $(boxId).html(html);
            pdfTimer = setInterval(function () {
                try {
                    clearInterval(pdfTimer);
                    pdfTimer = null;
                    var obj = document.getElementById(id);
                    obj.OpenWebDocument('https://inv.jss.com.cn/group4/M02/0C/1D/wKj6yFv6rEOIFSa7AAB4j4JYLowAAChmgDvq3EAAHin643.pdf');
                } catch (err) {
                    layer.alert('请安装pdf控件');
                }
            }, 700);
        },
        //圈阅意见
        circle: function () {
            //obj.DoStamp();
            top.layer.open({
                type: 2,
                title: '圈阅意见',
                area: configureCom.Psize1,
                content: configureCom.nocache(configure.EXPERT_ADD_SUGGEST_HTML),
                btnAlign: 'c',
                btn: ['保存', '取消'],
                yes: function (index, layero) {
                    var iframeWin = top.window.frames['layui-layer-iframe' + index];
                    iframeWin.getData().then(function (res) {
                        var data = res.result;
                        suggest.add(data).then(function (res) {
                            top.layer.alert('添加成功！');
                            var obj = document.getElementById("iStylePDF");
                            var FileID = matchType.init(drawingData.id);
                            var MarkupInfo = obj.GetMarkupInfo();
                            obj.SetMarkupInfo(FileID, MarkupInfo);
                        });
                        top.layer.close(index);
                    });
                }
            });
        },
        //修改意见
        amendments: function () {
            obj.GetMarkupInfo();//获取当前文档对应的圈阅信息字符串
            pdfXiaoling.init('iStylePDF', url, '#content');//更新图纸
        }
    };
    exports('pdfXiaoling', pdfXiaoling);
});